package com.ht.web360.ObjServer.controller;

import com.ht.web360.ObjServer.service.ObjService;
import com.ht.web360.base.dto.ObjInfo.dto.ObjInfoDto;
import com.ht.web360.base.dto.RPage;
import com.ht.web360.base.dto.Res;
import com.ht.web360.base.enums.UserType;
import com.ht.web360.base.utils.interfaces.RequireUserType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

@Tag(name = "对象数据控制器")
@RestController
@RequestMapping("/obj/info")
public class ObjInfoController {
    private final ObjService objService;

    public ObjInfoController(ObjService objService) {
        this.objService = objService;
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据id获取对象信息")
    @RequireUserType(UserType.Public)
    public Res<ObjInfoDto> getObjInfo(@PathVariable long id) {
        ObjInfoDto objInfoById = objService.getObjInfoById(id);
        return Res.ok(objInfoById);
    }

    @GetMapping("/page")
    @RequireUserType(UserType.User)
    @Operation(summary = "分页查询对象信息")
    public Res<RPage<ObjInfoDto>> pageObjInfo(
            @RequestParam("current") long current,
            @RequestParam("size") long size
    ) {
        RPage<ObjInfoDto> page = objService.pageObjInfo(current, size);
        return Res.ok(page);
    }

    @PostMapping("/update")
    @RequireUserType(UserType.User)
    @Operation(summary = "更新对象信息")
    public Res<Void> updateObjInfo(@RequestBody ObjInfoDto objInfoDto) {
        objService.updateObj(objInfoDto);
        return Res.ok();
    }

    @GetMapping("/delete/{id}")
    @RequireUserType(UserType.User)
    @Operation(summary = "删除对象")
    public Res<Void> deleteObjInfo(@PathVariable long id) {
        objService.deleteObj(id);
        return Res.ok();
    }
}
